package net.adetech.cjg.innerservice.controller;


import com.alibaba.fastjson.JSONObject;
import net.adetech.cjg.innerservice.entity.Qzb;
import net.adetech.cjg.innerservice.entity.Sqjl;
import net.adetech.cjg.innerservice.mapper.QzbDao;
import net.adetech.cjg.innerservice.mapper.SqjlDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TempController {


    @Autowired
    SqjlDao sqjlDao;

    @Autowired
    QzbDao qzbDao;

    @RequestMapping(value = "/temp/refreshSign", produces = "application/json")
    public String refreshSign(){

        int count = 0;
        List<Sqjl> sqjlList = sqjlDao.getAllSqjl();
        for (Sqjl sqjl:sqjlList
             ) {
            JSONObject ymJson = JSONObject.parseObject(sqjl.getYmJson());
            String yhbh = ymJson.getJSONObject("form").getString("userName");
            String mySign = ymJson.getJSONObject("form").getString("mySign");
            if (yhbh!=null&&mySign==null)
            {
                Qzb qzb = qzbDao.getQmbByYhzh(yhbh);
                if (qzb!=null)
                {
                    mySign = qzb.getQzImg();
                    ymJson.getJSONObject("form").put("mySign",mySign);
                    sqjlDao.updateYmJson(sqjl.getLsh(),ymJson.toJSONString());
                    count++;
                }
            }
        }

        return "{count:"+count+"}";
    }

}
